public class immediatelyActivateHCP{

    String hId = System.currentPageReference().getParameters().get('id');
    List<HCP__c> target = [select id,approvalstatus__c,effectivedate__c from HCP__c where Id =: System.currentPageReference().getParameters().get('id')];
    
    public HCP__c hcp{
        get{
            if (hcp==null)
                if(target.size() > 0){
                    hcp= target[0];
                }
                else
                    hcp= null;
            return hcp;
        }
        set;
    }
    
    public PageReference Submit() {
        if(hcp.approvalstatus__c =='审批通过但未生效'){
            hcp.effectivedate__c=date.today();
            hcp.approvalstatus__c='审批通过';
            update hcp;}
            return  new ApexPages.StandardController(new HCP__c(Id = hId)).view();    
           
    }
    
    static testMethod void immediatelyActivateHCPTest(){
        immediatelyActivateHCP testcase = new immediatelyActivateHCP();
        
        Hospital__c hos = new Hospital__c();
        hos.Name = 'aaaaaaaa';
        hos.Nickname__c = 'aaaaaaaaaaa';
        insert hos;
        
        HCP__c hcp= new HCP__c();
        hcp.class1__c = '全国学术带头人(NKOL)';
        hcp.Hospital__c = hos.Id;
        hcp.Active__c = true;
        insert hcp; 
        
        testcase.target = new List<HCP__c>();
        if(testcase.target.size() <= 0){
            testcase.target.add(hcp);
        }
        else{
            testcase.target[0] = hcp;
        }
      
        testcase.hcp.approvalstatus__c = '审批通过但未生效';
        testcase.Submit();
    }
}